home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
8174
/
8174.xpi
/
chrome
/
antbar.jar
/
content
/
toolbar.js
next >
Wrap
Text File
|
2009-12-30
|
7KB
|
243 lines
//
// toolbar.js
// antbar
//
// Created by Zak on 2008-06-11.
// Contributor Brian King (http://briks.si)
// Copyright 2008-2009 Ant.com. All rights reserved.
//
var AntBar =
{
searchType: 'web',
cleanedSearchBox: false,
/**
* Entry point of our toolbar, called before the loading of the homepage,
* but after that the toolbar has been rendered
*/
rankLabels: {
'statusbar-button': 'ant-video-statusbar-rank',
'statusbar-separator': 'ant-video-statusbar-rank-separator',
'toolbar-button': 'antToolBarRankButton',
},
init: function ()
{
var self = AntBar;
try {
AntFlvUi.init(document);
AntDownloadManager.init();
AntFlvList.init();
AntRankService.init();
AntGrabber.init();
AntPrefs.init();
AntWatchUrl.init();
AntBugReport.init();
}
catch(e) {
AntLib.toLog("AntBar.init error : " + e);
}
AntRankService.updateVisible();
this.UninstallObserver.register();
},
// http://xulsolutions.blogspot.com/2006/07/creating-uninstall-script-for.html
UninstallObserver : {
_uninstall : false,
observe : function(subject, topic, data) {
if (topic == "em-action-requested") {
subject.QueryInterface(Components.interfaces.nsIUpdateItem);
if (subject.id == "anttoolbar@ant.com") {
if (data == "item-uninstalled") {
this._uninstall = true;
AntLib.openURL('http://www.ant.com/video-downloader/uninstalled/');
} else if (data == "item-cancel-action") {
this._uninstall = false;
}
}
} else if (topic == "quit-application-granted") {
if (this._uninstall) {
AntPrefs.removeAntUserAgent();
AntPrefs.cleanEnvironement();
}
this.unregister();
}
},
register : function() {
var observerService =
Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "em-action-requested", false);
observerService.addObserver(this, "quit-application-granted", false);
},
unregister : function() {
var observerService =
Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this,"em-action-requested");
observerService.removeObserver(this,"quit-application-granted");
}
},
/**
* Handle search using terms typed in the antToolBarSearchBox
* @param type The type of search (web,image,video,news,blog)
*/
doSearch: function ()
{
var searchTermsBox = AntLib.ob("antToolBarSearchBox");
var searchTerms = AntLib.trim(searchTermsBox.value);
if (searchTerms.length == 0 || !this.cleanedSearchBox)
AntLib.openURL('http://www.ant.com/');
else
AntLib.openURL('http://www.ant.com/'+ this.searchType + '/'+AntLib.uriEncode(searchTerms));
},
/**
* Called when clicking on the "Support" button
*/
onSupportButtonClick: function (event)
{
AntLib.openURL('http://www.ant.com/toolbar/firefox/help', 1);
AntLib.ob('antToolBarCombinedButton').style.borderSpacing = 0;
},
/**
* Called when clicking on the "Download" button
*/
onDownloadButtonClick: function (aButton)
{
var doc = gBrowser.selectedBrowser.contentDocument;
if (doc.__antflv__ && doc.__antflv__.length != 0)
AntFlvList.download(doc.__antflv__[0]);
},
/**
* Called when clicking on a video in the download list
*/
onDownloadListClick: function (id)
{
var doc = gBrowser.selectedBrowser.contentDocument;
if (doc.__antflv__ && id < doc.__antflv__.length)
{
AntFlvList.download(doc.__antflv__[id]);
}
},
/**
* Called when clicking on the "open directory" button
*/
onOpenDirButtonClick: function (event)
{
var pref = AntPrefs.getAntBranch();
if (!pref)
{
alert(AntLang.getString("AntDownloadManager.InvalidDestinationFolder"));
return;
}
var dir = pref.getCharPref("flvdir");
flvDir = AntLib.CCSV("@mozilla.org/file/directory_service;1", "nsIProperties").get("ProfD", AntLib.CI("nsILocalFile"));
flvDir.initWithPath(dir);
try
{
flvDir.reveal();
}
catch (e)
{
try
{
AntLib.openExternal(flvDir);
}
catch (e2)
{
AntLib.toLog("reveal error : " + e);
AntLib.toLog("openExternal error : " + e2);
alert("This functionnality is not available on your operating system");
}
}
},
/**
* Called when click on the rank button
*/
onRankButtonClick: function ()
{
AntRankService.goProfil();
},
/**
* Called when clicking on the "Player" button
*/
onPlayerButtonClick: function (event)
{
AntLib.openURL("chrome://antbar/content/player/player.xul", true);
},
/**
* Clear the searchbox the first time user enter it
* @param isFocus true if the callback is onFocus otherwise false
*/
onSearchBoxOnFocus: function (isFocus)
{
if (!this.cleanedSearchBox && isFocus)
{
AntLib.ob('antToolBarSearchBox').value = '';
this.cleanedSearchBox = true;
}
if (!isFocus && !AntLib.ob('antToolBarSearchBox').value)
{
this.cleanedSearchBox = false;
}
},
/**
* Handle keystrokes entered in the searchBox
* @param event The event that triggered the call to this function
*/
onSearchBoxKeyPress: function (event)
{
if (event.keyCode == event.DOM_VK_RETURN)
{
if (AntLib.ob('antToolBarSearchBox').value != '')
this.doSearch();
else
AntLib.openURL('http://www.ant.com/');
}
},
/**
* Open the ant prefs window
*/
doPrefs: function ()
{
var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
var prefServiceCache = prefSvc.getBranch(null);
var instantApply = prefServiceCache.getBoolPref("browser.preferences.instantApply");
var flags = "chrome,titlebar,toolbar,centerscreen" + (instantApply ? ",dialog=no" : ",modal");
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Ant:Preferences");
if (win) {
win.focus();
}
else
{
window.openDialog("chrome://antbar/content/xul/options.xul",
"antpreferences",
flags);
}
},
}